package acwing;

import java.io.*;
import java.util.*;

public class ac799 {
    static final int N = 100010;
    static int[] a = new int[N];
    static int[] s = new int[N];
    static int n;
    static int res = 0;
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(in.readLine());
        String[] s1 = in.readLine().split(" ");
        for(int i = 1; i <= n; i ++ ) a[i] = Integer.parseInt(s1[i - 1]);
        for(int i = 1, j = 1; i <= n; i ++ ){
            s[a[i]] ++ ;
            while(j < i && s[a[i]] > 1){
                s[a[j ++ ]] -- ;
            }
            res = Math.max(res, i - j + 1);
        }

        System.out.println(res);
    }
}
